﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using System.Data.SqlTypes;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using Jungle.Code.BLL;
using Jungle.Code.Utils;
using System.Collections.Generic;
using Jungle.Code.DAL;

using Jungle.Code.BookManager;
using System.Drawing;
using Jungle.Code.Core;


namespace Jungle.Modules
{
    public partial class BooksUser : BaseUserModule
    {
        string cmd = "";
        string bId = "";
        string catId = "";


        protected override void OnInit(EventArgs e)
        {
            if (Request["cmd"] != null)
                cmd = Request["cmd"];
            if (Request["bId"] != null)
                bId = Request["bId"];
            if (Request["catId"] != null)
                catId = Request["catId"];

            switch (cmd)
            {
                case "view":
                    GlobalMenu.ActiveViewIndex = 0;
                    break;
                case "details":
                    GlobalMenu.ActiveViewIndex = 1;
                    PrepareView(Convert.ToInt32(bId));
                    break;
                default:
                    GlobalMenu.ActiveViewIndex = 0;
                    break;
            }


            base.OnInit(e);
        }

        //--------------------------------------------------------------------------------
        public void PrepareView(int bId)
        {
            Book dBook = new Book(bId);
            string sUrl = UrlHelper.GetSiteUrl();

            if (dBook.ImagePath != "no_photo") { img_Image.ImageUrl = sUrl + dBook.ImagePath; } else { img_Image.ImageUrl = "/UserFiles/Images/Content/no_photo.jpg"; }
            lbl_Title.Text = "<strong>Название: </strong>" + dBook.Title.Trim();
            lbl_Author.Text = "<strong>Автор: </strong>" + dBook.Author.Trim();
            lbl_Publisher.Text = "<strong>Издатель: </strong>" + dBook.Publisher.Trim();
            lbl_PubYear.Text = "<strong>Год: </strong>" + dBook.PubYear.ToString().Trim();
            lbl_Pages.Text = "<strong>Страниц: </strong>" + dBook.PagesCount.ToString().Trim();
            lbl_Format.Text = "<strong>Формат: </strong>" + dBook.Format.Trim();
            lbl_Size.Text = "<strong>Размер файла: </strong>" + dBook.SizeMb.ToString().Trim();
            lbl_Quality.Text = "<strong>Качество: </strong>" + dBook.Quality.Trim();
            lbl_Series.Text = "<strong>Серия: </strong>" + dBook.Series.Trim();
            lbl_Language.Text = "<strong>Язык: </strong>" + dBook.Language.Trim();
            if (dBook.Price != 0)
            {
                lbl_Price.Text = "<strong>Цена: </strong>" + dBook.Price.ToString().Trim();
            }
            else 
            {
                lbl_Price.Text = "<strong>Цена: </strong> Бесплатно";
            }
            lbl_DownloadLink.Text = "<a href='" + dBook.DownloadPath.Trim() + "'><strong>Скачать</strong></a>";
            lbl_Description.Text = "<strong>Описание: </strong>" + dBook.Description.Trim();
        }
    }
}